<?php
/**
 * Created by PhpStorm.
 * User: zhangrxiang
 * Date: 17-1-18
 * Time: 上午10:59
 */

$a = 'hello';
//可变变量
$$a = "World";

echo $a.$$a.PHP_EOL;//helloWorld


class foo {
    var $bar = 'I am bar.'.PHP_EOL;
    var $arr = array('I am A.'.PHP_EOL, 'I am B.'.PHP_EOL, 'I am C.'.PHP_EOL);
    var $r   = 'I am r.'.PHP_EOL;
}

$foo = new foo();
$bar = 'bar';
$baz = array('foo', 'bar', 'baz', 'quux');
echo $foo->$bar;//I am bar.
echo $foo->{$baz[1]};//I am bar.

$start = 'b';
$end   = 'ar';
echo $foo->{$start . $end};

$arr = 'arr';
echo "........".PHP_EOL;
echo $foo->$arr[1];//I am B.
echo "........".PHP_EOL;
echo $foo->{$arr}[1];//I am B.
echo "........".PHP_EOL;
echo ($foo->$arr)[1];//I am B.
echo "........".PHP_EOL;

echo $foo->r;
$r = "r";
echo $foo->$r;


$Bar = "a";
$Foo = "Bar";
$World = "Foo";
$Hello = "World";
$a = "Hello";

echo PHP_EOL.$a; //Returns Hello
echo PHP_EOL.$$a; //Returns World
echo PHP_EOL.$$$a; //Returns Foo
echo PHP_EOL.$$$$a; //Returns Bar
echo PHP_EOL.$$$$$a; //Returns a
echo PHP_EOL.$$$$$$a; //Returns Hello
echo PHP_EOL.$$$$$$$a; //Returns World


